Developer API

Game Audio

Namespace: $GG.ui.audio

The $GG.ui.audio namespace is designed to handle all audio operations within the Gig Games application. It provides a comprehensive suite of functions that enable developers to manage audio playback effectively. With these functions, you can play, stop, and manipulate audio files seamlessly, allowing for dynamic audio control that enhances the gaming experience.

Include In Html

<head>
    ...
    <script src="https://launch.gig.game/api/js?key={API KEY HERE}&libraries=ui"></script>
    ...
</head>

Key Features

  • Audio Playback: Play background music, sound effects, and other audio elements to enrich the gaming environment.
  • Dynamic Audio Control: Adjust volume levels, loop audio tracks, and create immersive soundscapes tailored to the game's needs.
  • Audio Manipulation: Perform advanced audio operations such as fading in and out, cloning audio instances, and stopping all audio with a single command.
  • Preloading: Preload audio assets to ensure smooth playback and reduce latency during gameplay.
  • Compatibility: Ensure audio plays correctly across different platforms and devices, including handling special cases like user interaction requirements on certain operating systems.

Key Functionality

  • Cloning Audio Instances: Each play of an audio file can be made into its own instance using the clone parameter. This is particularly useful when you need to play the same sound multiple times simultaneously, such as in rapid succession or overlapping scenarios.
  • Stopping Cloned Audio: To stop a cloned audio instance early, you need to pass the audio instance to the stop function instead of just the string name. This ensures that the specific instance of the sound is correctly identified and stopped.

Usage Scenarios

  1. Background Music: Set the mood with looping background tracks that adjust to different game scenes.
  2. Sound Effects: Enhance interactivity with responsive sound effects for user actions and game events.
  3. Voice Overs: Implement character voice overs and narrations for a more engaging story-driven experience.
  4. Audio Feedback: Provide audio feedback for UI interactions, making the game feel more responsive and polished.
  5. Simultaneous Sound Effects: Use cloned audio instances to handle scenarios where the same sound needs to be played multiple times at once, such as explosions or rapid-fire effects.

Best Practices

  • User Interaction: Some operating systems, like OSx, may require a user interaction (such as a tap or button press) before audio can be played. To ensure smooth audio playback, consider implementing a start button that users must press to enter the game before any audio assets are loaded.
  • Asset Management: Preload critical audio assets to minimize load times and prevent audio lag during gameplay.
  • Volume Control: Provide users with options to adjust audio settings, including master volume, music volume, and sound effects volume, to cater to their preferences.
  • Testing: Test audio playback across various devices and platforms to ensure a consistent and high-quality audio experience for all users.
  • Managing Cloned Audio: When using the clone parameter to create multiple instances of the same sound, ensure you manage these instances correctly, stopping them individually as needed by passing the instance to the stop function.
  • Consistent Naming: The names passed into the audio functions should match those preloaded with or loaded from the asset sheet to ensure proper identification and usage of the audio assets.

By leveraging the capabilities of the $GG.ui.audio namespace, developers can create rich and immersive audio experiences that significantly enhance the overall gaming experience on the Gig Games platform.